package net.hctek.AnnouncerStation.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;

import net.hctek.AnnouncerStation.bean.Files;
import net.hctek.AnnouncerStation.bean.Navs;
import net.hctek.AnnouncerStation.service.IdentityServiceI;
import net.hctek.AnnouncerStation.util.ResponseJsonUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class FilesListAction  extends ActionSupport {
	
	private static final long serialVersionUID = 1L;

	@Autowired
	private IdentityServiceI identityService;
	
	public String showFilesList(){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.addHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
		response.addHeader("Access-Control-Allow-Headers", "Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With");
		try {
			List<Map<String,String>> FilesList = identityService.showFilesList();
			JSONArray json = new JSONArray();
			 for(Map<String, String> f : FilesList){
	                JSONObject jo = new JSONObject();
	                jo.put("FilesId", f.get("FilesId"));
	                jo.put("FilesName",f.get("FilesName"));
	                /*jo.put("FilesPath",f.getFilesPath());*/
	                jo.put("FilesSize",f.get("FilesSize"));
	                jo.put("FilesTime",f.get("FilesTime"));
	                json.add(jo);
	            }
			System.out.println(json.toString());
			ResponseJsonUtils.json(response, json);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return NONE;
	}

}
